package com.sicheng.metadata.juc.jmm;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/1/19 22:50
 */
public class 指令重排 {

    static int x = 0, y = 0;
    static int a = 0, b = 0;

    public static void main(String[] args) throws InterruptedException {

        while (true) {
            x = 0;
            y = 0;
            a = 0;
            b = 0;
            Thread one = new Thread(() -> {
                a = 1;
                x = b;
            });

            Thread other = new Thread(() -> {
                b = 1;
                y = a;
            });
            one.start();
            other.start();
            one.join();
            other.join();
            System.out.println("(" + x + "," + y + ")");
            Thread.sleep(100);
        }
    }

}
